package com.caseProject.puremvc.mediator.gui
{
	import com.caseProject.puremvc.mediator.events.GraphicEvent;
	import com.caseProject.puremvc.model.vo.ElementVO;
	
	import flash.display.NativeMenuItem;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	public class Element extends AbstractGraphicBehavior
	{
		public function Element()
		{
			super();
			
			var front:NativeMenuItem = new NativeMenuItem("Trazer Para Frente");
			var back:NativeMenuItem = new NativeMenuItem("Enviar Para Trás");
			
			this.contextMenu.addItem(front);
			this.contextMenu.addItem(back);
			
			front.addEventListener(Event.SELECT, onSelectFront);
			back.addEventListener(Event.SELECT, onSelectBack);			
		}
		
		override protected function onMove(event:MouseEvent):void
		{
			super.onMove(event);
			
			var elementVO:ElementVO = ElementVO (this.vo);
			elementVO.posX = this.x;
			elementVO.posY = this.y;
		}
		
		override protected function onSelectDel(event:Event):void
		{
			this.dispatchEvent(new GraphicEvent(GraphicEvent.DELETE_ELEMENT, this.vo, true));
			this.parent.removeChild(this);			
		}
		
		protected function onSelectBack(event:Event):void
		{
			if (this.parent != null && this.parent.contains(this))
			{
				this.parent.addChildAt(this,0);
			}			
		}
		
		protected function onSelectFront(event:Event):void
		{
			if (this.parent != null && this.parent.contains(this))
			{
				this.parent.addChildAt(this,this.parent.numChildren-1);
			}
		}
		
		override public function draw ():void{
			super.draw();
		}
		
		public function rename(vo:ElementVO):void{}
		
		public function redraw(w:Number = 100, h:Number = 50):void{}
	}
}